Skip to content

Conversation

andrewn617
Copy link
Member

@andrewn617 andrewn617 commented Mar 1, 2025

When you run a rake task with bin/rails it does not use spring (except db rake tasks). And, many rails commands that could benefit from using spring do not use it, since the current system is for commands to opt-in.

I believe that it would be better to have an opt-out system rather than an opt-in system, since likely most commands and tasks will benefit from spring. So I implemented that in this PR.

While here I simplified the existing Rails sub-commands implementation, which had varying ways of picking off the environment from the args. I believe we only need one special subcommand, test because it needs to default to the test environment, unlike the others.

I opted out the server command because it should not run with spring. Are there any other commands that should opt-out?

Previously, bin/rails only used spring for a subset of commands and
rake tasks. However, most rake tasks can benefit from spring and do
use spring when using bin/rake.

This PR makes rake tasks run with bin/rails use spring, and introduces
and opt-out system for certain Rails commands that should not use spring
(like the server) instead of the previous opt-in system.
@rafaelfranca rafaelfranca merged commit 4126e5e into rails:main Jul 21, 2025
6 checks passed
@rafaelfranca rafaelfranca deleted the default-to-using-spring-with-rails branch July 21, 2025 20:19
rafaelfranca added a commit that referenced this pull request Aug 1, 2025
…with-rails"

This reverts commit 4126e5e, reversing
changes made to 046d50a.
rafaelfranca added a commit that referenced this pull request Aug 1, 2025
…with-rails"

This reverts commit 4126e5e, reversing
changes made to 046d50a.

Reason: This was breaking regular `bin/rails test some_file.rb` usage
because the the first arg was being removed from the command line.
@rafaelfranca
Copy link
Member

This changed bin/rails test foo.rb to drop the test argument when calling the rails command in the spring server.

BEFORE SPRING: ["test", "test/unit/database_schema_test.rb"]
IN bin/spring
DOING STUFF IN bin/spring
Running via Spring preloader in process 95635
running spring after_fork
BEFORE SPRING: ["test/unit/database_schema_test.rb"]
IN bin/spring
AFTER SPRING: ["test/unit/database_schema_test.rb"]
Unrecognized command "test/unit/database_schema_test.rb" 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants